package com.cjk.foundation.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	public static String format(Date date, String format){
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		return simpleDateFormat.format(date);
	}
	
	public static Date getTimeDaysAfter(Date date, Integer days){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + days);
		return calendar.getTime();
	}
	
	public static Date getTimeYearsAfter(Date date, Integer year){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + year);
		return calendar.getTime();
	}
	
	public static Date getTimeMinuteAfter(Date date, Integer minute){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) + minute);
		return calendar.getTime();
	}
	
	public static String getTime(Date date){
		final String format = "yyyy-MM-dd HH:mm:ss";
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		return simpleDateFormat.format(date);
	}
	
	public static Long subDate(Date minuend, Date subtrahend){
		long l = minuend.getTime() - subtrahend.getTime();
//		long day = l / (24 * 60 * 60 * 1000);
//		long hour = (l / (60 * 60 * 1000) - day * 24);
//		long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
//		long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
//		System.out.println(""+day+"天"+hour+"小时"+min+"分"+s+"秒");
		return l / (60 * 1000);
	}
	
	public static void main(String[] args) {
		Date now = new Date();
		Date after = getTimeYearsAfter(now, 100);
		System.out.println(getTime(now));
		System.out.println(getTime(after));
	}
}
